package com.app.service.impl;

import com.app.dao.ShareDao;
import com.app.pojo.Share;
import com.app.pojo.Status;
import com.app.service.IShareService;
import org.springframework.stereotype.Service;

@Service
public class ShareService implements IShareService {
    ShareDao shareDao;

    public ShareService(ShareDao shareDao) {
        this.shareDao = shareDao;
    }

    @Override
    public int addShare(Share share) {
        Share old=shareDao.findShareByIdPath(share.userId,share.path);
        if (old==null){
             return shareDao.addShare(share)==1? Status.SUCCESS:Status.FAIL;
        }
        return Status.SHARE_ALREADY_EXIST;
    }

    @Override
    public Share[] findSharesById(String userId) {
        return shareDao.findSharesById(userId);
    }

    @Override
    public Share[] searchSharesByPath(String path) {
        return shareDao.searchSharesByPath(path);
    }

    @Override
    public Share findShareByIdPath(String userId, String path) {
        return shareDao.findShareByIdPath(userId, path);
    }

    @Override
    public int delShareByIdPath(String userId, String path) {
        return shareDao.delShareByIdPath(userId, path)==1? Status.SUCCESS:Status.FAIL;
    }
}
